package cc.sunni.user.controller;

import cc.sunni.api.BaseController;
import cc.sunni.api.controller.user.MyFansControllerApi;
import cc.sunni.common.enums.Sex;
import cc.sunni.common.utils.R;
import cc.sunni.pojo.vo.FansCountsVO;
import cc.sunni.user.service.FansService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyFansController extends BaseController implements MyFansControllerApi {
    @Autowired
    private FansService myFanService;

    @Override
    public R isMeFollowThisWriter(String writerId, String fanId) {
        boolean res = myFanService.isMeFollowThisWriter(writerId, fanId);
        return R.ok(res);
    }

    @Override
    public R follow(String writerId, String fanId) {
        myFanService.follow(writerId, fanId);
        return R.ok();
    }

    @Override
    public R unfollow(String writerId, String fanId) {
        myFanService.unfollow(writerId, fanId);
        return R.ok();
    }

    @Override
    public R queryAll(String writerId, Integer page, Integer pageSize) {
        return R.ok(myFanService.queryMyFansList(writerId, page, pageSize));
    }

    @Override
    public R queryRatio(String writerId) {
        int manCounts = myFanService.queryFansCounts(writerId, Sex.man);
        int womanCounts = myFanService.queryFansCounts(writerId, Sex.woman);
        FansCountsVO fansCountsVO = new FansCountsVO();
        fansCountsVO.setManCounts(manCounts);
        fansCountsVO.setWomanCounts(womanCounts);
        return R.ok(fansCountsVO);
    }

    @Override
    public R queryRatioByRegion(String writerId) {
        return R.ok(myFanService.queryRegionRatioCounts(writerId));
    }
}
